﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using SLIITPro.Data.Extension;
using SLIITPro.Data.Entity;

namespace SLIITPro
{
    public partial class activation : System.Web.UI.Page
    {
        private UserExtension _userExtension;
        private Users _users;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (IsPostBack) return;
            if (!string.IsNullOrEmpty(Request.QueryString["ac"]))
            {
                try
                {
                    _userExtension = new UserExtension();
                    var userRow = _userExtension.SelectUser("ActivationCode", Request.QueryString["ac"].Trim());
                    _users = new Users(userRow.Rows[0]);
                    if (!Convert.ToBoolean(_users.IsActivated))
                    {
                        _userExtension.ChangeActivationMode(true, _users.UserId);
                        lnkThnkLogin.Text =
                            string.Format("{0} {1}, your account activation succeeded. Click here to login to system",
                                          _users.FirstName,
                                          _users.LastName);
                    }
                    else
                    {
                        lnkThnkLogin.Text =
                            string.Format("User {0} {1} already activated. Click here to login to system",
                                          _users.FirstName,
                                          _users.LastName);

                    }
                }
                catch
                {
                    lnkThnkLogin.Text = "Error occured. Click here to go to home page";
                }
            }
        }
    }
}